//
//  KKStatus.swift
//  KKWeibo
//
//  Created by kassia on 16/7/14.
//  Copyright © 2016年 kassia. All rights reserved.
//

import UIKit

class KKStatus: NSObject {


    var created_at: String?    //  发布微博时间

    var id: Int64 = 0    //  微博id

    var text: String?    //  微博内容

    var source: String?    //  来源
    
    var user: KKUser?    //用户对象信息
    
    var reposts_count: Int = 0  //  转发数
    
    var comments_count: Int = 0 //  评论数
    
    var attitudes_count: Int = 0 //  表态数(赞)
    
    var retweeted_status: KKStatus? //微博转发内容
    
    var pic_urls: [KKStatusPictureInfo]?
    
    //kvc构造函数
    init(dic: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
        
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
        
            guard let dic = value as? [String: AnyObject] else {
            
                return
            }
            //代码执行到此,一定使我们想要的字典格式
            user = KKUser(dic: dic)
  
        } else if key == "retweeted_status" {
        
            guard let dic = value as? [String: AnyObject] else {
            
                return
            
            }
            
            retweeted_status = KKStatus(dic: dic)
        
        } else if key == "pic_urls"{
        
            guard let dictArray = value as? [[String: AnyObject]] else {
            
                return
            
            }
            
            var tempArray = [KKStatusPictureInfo]()
            
            // 代码执行到此一定有值
            for dict in dictArray {
            
                let pic = KKStatusPictureInfo(dict: dict)
                
                tempArray.append(pic)
            }
        
            pic_urls = tempArray // 对图片字典数组赋值
            
        } else {
            
           super.setValue(value, forKey: key)
        }

    }
    //防止字段不匹配造成的崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
